﻿using System;
using System.Collections.Generic;
using System.Text;

using GotLyrics.LyricGrabbers.LyricWiki;

using LyricWikiService = GotLyrics.LyricGrabbers.LyricWiki.LyricWiki;

namespace GotLyrics.LyricGrabbers
{
    public class LyricWikiGrabber : LyricGrabber
    {
        // public LyricWikiGrabber() { Enabled = false; }

        /// <summary>
        /// The website of this lyrics provider. This is pointing to the main page on the website.
        /// </summary>
        /// <value></value>
        public override string WebSiteUrl
        {
            get { return "http://lyricwiki.org/"; }
        }

        /// <summary>
        /// Grabs the lyric based on the current <see cref="Context"/> from the webservice.
        /// </summary>
        /// <returns>
        /// The lyric if one was found, otherwise <c>null</c>.
        /// </returns>
        protected override string GrabLyric(LyricGrabberContext context)
        {
            string artist = context.Tags.Artist;
            string title = context.Tags.Title;

            LyricWikiService service = new LyricWikiService();

            if (service.checkSongExists(artist, title))
            {
                LyricsResult result = service.getSong(artist, title);

                if (result != null && !string.IsNullOrEmpty(result.lyrics) &&
                    result.lyrics != "Not found") // Such a beautiful website and they do something like this :S
                    return result.lyrics.Replace("\n", "\r\n");
            }
    
            return null;
        }
    }
}
